Filter to remove samples withough any clone > 0.01

(if low_prev = TRUE, this step is skipped)

### If only high-prevalence clones being displayed, remove microbiopsies without any clones >0.01 (otherwise mapscape fails)
if (low_prev == FALSE) {
  print("removing low prevelence (<0.01) samples from display")

  max_prev <- prev_tbl_filt %>%
    dplyr::group_by(sample_id) %>%
    dplyr::summarise(max_prev = max(clonal_prev))
  high_prev_samples <- max_prev %>%
    dplyr::filter(max_prev >= 0.03) %>%
    dplyr::select(sample_id)
  removed_samps <- max_prev %>%
    dplyr::filter(max_prev < 0.03) %>%
    dplyr::select(sample_id)
  removed_samps <- removed_samps$sample_id
  high_prev_samples <- high_prev_samples$sample_id
  print(removed_samps)
  prev_tbl_filt <- prev_tbl_filt %>%
    dplyr::filter(sample_id %in% high_prev_samples)
  location_tbl <- location_tbl %>%
    dplyr::filter(sample_id %in% high_prev_samples)
  
  # filter mut table to only inclde samples/clones present
  present_clones <- unique(prev_tbl_filt$clone_id)
  if (exists("mut_tbl_final")) {
      mut_tbl_final <- mut_tbl_final %>%
    dplyr::filter(sample_id %in% high_prev_samples,
                  clone_id %in% present_clones) 
  }
} else {
  print("Low prevelence clones displayed, entire tree included")
}
## [1] "removing low prevelence (<0.01) samples from display"
## factor()
## 15 Levels: b_0049 b_0052 b_0054 b_0056 b_0059 b_0065 b_0072 b_0075 ... b_0095

Display cluster diagram

cluster_diagram_file <- paste0(ndp_dir, "/Cluster_and_spectrum_plots.pdf")

Display per-cluster mutation counts

mut_counts %>%
  kable %>%
  kable_styling("striped", full_width = F) %>%
  scroll_box(width = "300px", height = "500px")
Cluster ID Mutations Assigned
Cl.1 1125
Cl.2 2677
Cl.3 1764
Cl.4 345
Cl.5 2670
Cl.6 284
Cl.7 344
Cl.8 1212
Cl.9 427
Cl.10 3505
Cl.13 3455
Cl.14 3891
Cl.15 2736
Cl.16 1071
Cl.17 4733
Cl.18 1232
Cl.21 2234
Cl.24 173
Cl.26 3041
Cl.27 217
Cl.31 3172
Cl.32 605
Cl.33 1201
Cl.34 359
Cl.36 3325
Cl.37 1277

Display Large Versions of Static Trees

Generate mapscape

if (exists("mut.file")) {
  print("mutation table found")
  mapscape(clonal_prev = prev_tbl_filt, 
         tree_edges = edge_tbl, 
         sample_locations = location_tbl,
         img_ref = image.file,
         static_tree_image = static_tree_file,
         width = 1500,
         height = 1300,
         show_low_prev_gtypes = low_prev,
         phylogeny_title = sample_name,
         anatomy_title = pat_age,
         clone_colours = color_tbl,
         mutations = mut_tbl_final)
} else {
  print("no mutation table found")
  mapscape(clonal_prev = prev_tbl_filt, 
           tree_edges = edge_tbl, 
           sample_locations = location_tbl,
           img_ref = image.file,
           static_tree_image = static_tree_file,
           width = 1500,
           height = 1300,
           show_low_prev_gtypes = low_prev,
           phylogeny_title = sample_name,
           clone_colours = color_tbl)
}
## [1] "mutation table found"
## [1] "[WARNING] Low prevalence genotypes will not be shown in the view. To show them, set show_low_prev_gtypes parameter to TRUE."